package com.kx.yooli.kx.wechat.utils.valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

/**
 * @author john_sqwen-childe.wen
 * date 2024/4/8
 * PROJECT_NAME wechat
 * description create ValidateCodeUtil by john_sqwen
 * and  value is
 */
public class ValidateCodeUtil
{
    private final Logger log = LoggerFactory.getLogger(ValidateCodeUtil.class);
    private static final String CHAR_LIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    private static final Integer CHAR_LEN = CHAR_LIST.length();
    /**
     * @return 生成一个六位随机数
     */
    public static String getcheckcode() {
        Random random = new Random();
        String result = "";
        for (int i = 0; i < 6; i++) {
            result += random.nextInt(10);
        }
        return result;
    }

    /**
     * @return 生成一个随机字符串
     */
    public static String getRandomString(Integer length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(CHAR_LIST.charAt(random.nextInt(CHAR_LEN)));
        }
        return sb.toString();
    }
}
